home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload Trio 2
/
Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO
/
dir41
/
zi.zip
/
ZI.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-01-14
|
4KB
|
167 lines
//
// Module: zi.cpp
// Version: 1.1
// Release: 101
// Date: 01/14/93 18:47:41
//
// ZI check for debug info in object file
//
// COPYRIGHT (C) 1992. All Rights Reserved.
// Baumeister Corporation. Granbury, Texas.
//
// Relaeased to the public domain by
//
// Louis F. Springer, CDP
// Baumeister Corporation
// 2A Thunderbird Cove
// Granbury, Texas 76049
// (817)326-5329
// CIS 73770,1137
//
//
// 1.0 01/14/93 LOU Initial rev.
// ------------------------------------------------
// 1.1 01/14/93 LOU Fixed error in case statement.
// ------------------------------------------------
//
// $nokeywords$
//
// Read the object files listed in standard in and output the source
// file name of the ones
// which have debug info on them to stdout.
//
// Example:
//
// dir *.obj /b | zi | awk "{cmd = \"touch \" $1; system(cmd);}"
//
// Will "touch" all files which have debug info in them. Useful to
// catch everything you've been debugging prior to a production
// complile.
//
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include "omf.h"
char *hasLinnum(char *objFile);
int getRec(FILE *in);
#define BUFSZ 1024
// rec static global used to hold omf records
static omf rec;
// remember the source file name in the obj file here
static char sourceFile[BUFSIZ];
extern int errno;
int main(int argc, char *argv[])
{
int numlines = 0;
char objFile[BUFSZ];
fgets(objFile, BUFSZ-1, stdin);
while(!feof(stdin) && !ferror(stdin))
{
numlines++;
// remove '\n'
char *nl = strchr(objFile, '\n');
if(nl) *nl='\0';
if(hasLinnum(objFile)) printf("%s\n", sourceFile);
fgets(objFile, BUFSZ-1, stdin);
}
return 0;
}
// does the object file specified have a LINNUM record?
// return the source file name
char *hasLinnum(char *objFile)
{
FILE *in = fopen(objFile, "rb");
rec.data = NULL; // initialize data
// initalize sourceFile to indicate no name in obj file
sprintf(sourceFile, "%s NO SOURCE NAME IN OBJ", objFile);
while(getRec(in))
{
switch(rec.hdr.type)
{
// should be the first reord in the file
// get the source file name
case OMF_THEADR:
{
omfTheadr *theadr = (omfTheadr *)rec.data;
sprintf(sourceFile, "%*.*s",
theadr->strlen, theadr->strlen, theadr->data);
}
break;
case OMF_LINNUM1:
case OMF_LINNUM2:
fclose(in);
return(sourceFile);
break;
}
}
fclose(in);
return NULL;
}
// get the next record from the obj file
int getRec(FILE *in)
{
if(rec.data) free(rec.data);
int itemsRead = fread(&rec.hdr, sizeof(rec.hdr), 1, in);
if(!itemsRead || feof(in) || ferror(in))
{
rec.hdr.type = 0x00;
rec.hdr.len = 0x00;
return 0;
}
rec.data = malloc(rec.hdr.len);
if(rec.data)
{
// read data
if(rec.hdr.len - 1)
{
itemsRead = fread(rec.data, rec.hdr.len - 1, 1, in);
if(feof(in) || ferror(in))
{
fprintf(stderr, "Error reading file.\n");
free(rec.data);
return 0;
}
}
// checksum
itemsRead = fread(&rec.checkSum, sizeof(rec.checkSum), 1, in);
if(feof(in) || ferror(in))
{
fprintf(stderr, "Error reading file.\n");
free(rec.data);
return 0;
}
return 1;
}
else
{
fprintf(stderr,
"Can't allocate %d bytes for buffer for record type 0x%.2xh.\n",
rec.hdr.len, rec.hdr.type);
return 0;
}
}